<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增上课时间')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-time-add">
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">节次：</label>
                <div class="col-sm-8">
                    <input name="section" id="section" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">节次编号：</label>
                <div class="col-sm-8">
                    <input name="sectionNumber" id="sectionNumber" class="form-control" type="number" placeholder="请填入阿拉伯数字同节次（第一节:填入1）" min="1" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上课时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="classStartTime" id="classStartTime" class="form-control" placeholder="HH:mm:ss" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">下课时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="classEndTime" id="classEndTime" class="form-control" placeholder="HH:mm:ss" type="text" required>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "website/classtime"
        $("#form-time-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var beginTime=$("#classStartTime").val();
            var endTime=$("#classEndTime").val();
            //设计表date型,修改牵扯多，直接设置统一年月日
            var beginTime1="1970-01-01 "+beginTime;
            var endTime1="1970-01-01 "+endTime;
               if ($.validate.form()) {
                   if(endTime<=beginTime){
                       $.modal.alertError("下课时间应大于上课时间")
                   }else{
                       //$.operate.save(prefix + "/add", $('#form-time-add').serialize());
                       $.ajax({
                           url : prefix + "/add",
                           type : 'post',
                           data : {"section":$("#section").val(),"sectionNumber":$("#sectionNumber").val(),"classStartTime":beginTime1,"classEndTime":endTime1},
                           dataType : 'json',
                           success : function (data) {
                               if(data.code==0){
                                   $.modal.msgReload("添加成功",'success');
                               }else if(data.code==500){
                                   $.modal.msgReload(data.msg,'error');
                               }
                           }
                       })
                   }

                }

        }

        $(function () {
            $("input[name='classStartTime']").datetimepicker({
                format:'hh:ii:00',
                startView:'day',
                maxView:'day',
                minView:'hour',
                minuteStep:1,
                autoclose:true,
                pickerPosition: "bottom-left",
                language:'zh-CN',
            });

            $("input[name='classEndTime']").datetimepicker({
                format:'hh:ii:00',
                startView:'day',
                maxView:'day',
                minView:'hour',
                minuteStep:1,
                autoclose:true,
                pickerPosition: "bottom-left",
                language:'zh-CN',
            });
        })

    </script>
</body>
</html>